#include <vector>
#include <string>
#include <iostream>

using namespace std;

string RunLengthEncoding(const string &str){
    string result;
    int count = 1;
    
    for(int i = 1; i < str.size(); ++i){
        if(str[i] == str[i - 1]){
            count++;
            if(count == 10){
                result.append(to_string(9));
                result.append(1, str[i-1]);
                count = 1;
            }
        }
        else{  
            result.append(to_string(count));
            result.append(1, str[i-1]);
            count = 1;
        }
    }
    return result;
}

int main(int argc, char const *argv[])
{
    string str{"aabbaaaaaaaaaa"};
    cout << RunLengthEncoding(str) << endl;
    return 0;
}
